﻿$(function () {
    $('#navigation li').removeClass('active');
    $('#menu_home').addClass('active');
    twiSelf.init();
    $('#checkInOut').click(function () {
        Twi.Ajax({
            data: {
                cn: 'SingleRecord',
                mn2: 'CheckInOut'
            },
            success: function (twi) {
                twiSelf.getCheckInfo();
                twiSelf.loadSelfCheckRecord();
                alert('打卡签到成功:' + twi.data);
            }
        });
    });

    $('#userRealName').html($.cookie('twi_scs_cookie_FRealName'));
});

Twi.SCS.Home = {
    Vars: {}
    , init: function () {
        twiSelf.getCheckInfo();
        twiSelf.loadSelfCheckRecord();
    }

    , getCheckInfo: function () {
        //打卡提示语等
        Twi.Ajax({
            data:
            {
                cn: 'SingleRecord',
                mn2: 'GetCheckInfo'
            },
            success: function (twi) {
                $('#welcomeInfo').html(twi.data);
                $('#checkInOut').html(twi.id);
            }
        });
    }

    , loadSelfCheckRecord: function () {
        //个人今日打卡记录
        Twi.Ajax({
            data:
            {
                cn: 'SingleRecord',
                mn2: 'GetSelfTodayCheckedRecord'
            },
            success: function (twi) {
                if (twi.totalCount > 0) {
                    var list = JSON.parse(twi.data);
                    $('#checkInOutRecord').html('');
                    for (var i = 0; i < list.length; i++) {
                        var itm = list[i];
                        $('#checkInOutRecord').append('<span>' + itm.FDate + ' ' + itm.FTime + '</span>');

                    }
                }
                else {
                    $('#checkInOutRecord').append('<span>今天还没有打卡记录</span>');
                }
            }
        });
    }
};


var twiSelf = Twi.SCS.Home;
var twiVars = twiSelf.Vars;


